package detector.audio;

import java.util.HashSet;
import java.util.Set;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import detector.audio.processing.AudioClip;
import detector.audio.processing.Monitor;
import detector.audio.processing.PeakHandler;
import detector.audio.processing.SoundClass;
import detector.home.AbstractTrainActivity;
import detector.home.R;

/**
 * Activity for adding training examples to a sound. If created and passed a
 * SoundClass through putExtra(), it will add the training examples to the
 * passed soundclass. If that isn't pased, it'll just create a new sound
 * (prompting the user for the name when done).
 * 
 * @author Kyle
 * 
 */
public class TrainActivity extends AbstractTrainActivity {

	private Activity thisActivity = this;
	private SoundClass toTrain;
	private Button btnFinish;
	private SoundClass toAddExamplesFor;
	private static final String TAG = "TrainActivity";

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.train);
		initializeTrainingViews();		
		
		//Figure out if this intent is a request to add examples to an existing
		// sound class
		// Get the soundclass the caller wants to add examples for, or null
		toAddExamplesFor = (SoundClass) getIntent()
				.getSerializableExtra("detector.audio.processing.SoundClass");
		
		setSoundClassToAddExamplesFor(toAddExamplesFor);	
		
		if (toAddExamplesFor == null) {
			//If we are making a new sound, make the training section active
			this.setTrainSectionActive(true);
		}
	}

	@Override
	public void finish() {
		Monitor.getMonitor().stopListening();
		setResult(RESULT_OK);
		super.finish();
	}

}
